<template>
  <a-drawer
    :title="title"
    :maskClosable="true"
    :width="drawerWidth"
    placement="right"
    :closable="true"
    @close="handleCancel"
    :visible="visible"
    style="height: calc(100% - 55px);overflow: auto;padding-bottom: 53px;">

    <template slot="title">
      <div style="width: 100%;">
        <span>{{ title }}</span>
        <span style="display:inline-block;width:calc(100% - 51px);padding-right:10px;text-align: right">
          <a-button @click="toggleScreen" icon="appstore" style="height:20px;width:20px;border:0px"></a-button>
        </span>
      </div>

    </template>
    
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">
      
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="应用编号">
          <a-input placeholder="请输入应用编号" v-decorator="['appId', validatorRules.appId ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="发起交易的 IP">
          <a-input placeholder="请输入发起交易的 IP" v-decorator="['createIp', validatorRules.createIp ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="业务线的订单编号">
          <a-input placeholder="请输入业务线的订单编号" v-decorator="['orderId', validatorRules.orderId ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="订单商品名">
          <a-input placeholder="请输入订单商品名" v-decorator="['orderSubject', validatorRules.orderSubject ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="订单商品描述">
          <a-input placeholder="请输入订单商品描述" v-decorator="['orderDescription', validatorRules.orderDescription ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="订单备注">
          <a-input placeholder="请输入订单备注" v-decorator="['orderMemo', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="支付金额">
          <a-input-number v-decorator="[ 'price', validatorRules.price ]" />
        </a-form-item>

        <a-form-item label="订单状态" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-select v-decorator="[ 'status', {}]" placeholder="请输入订单状态">
            <a-select-option :value="1">等待支付</a-select-option>
            <a-select-option :value="2">支付成功</a-select-option>
            <a-select-option :value="3">取消支付</a-select-option>
          </a-select>
        </a-form-item>

        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="交易过期时间">
          <a-date-picker showTime format='YYYY-MM-DD HH:mm:ss' v-decorator="[ 'expireTime', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="回调业务线完成时间">
          <a-date-picker showTime format='YYYY-MM-DD HH:mm:ss' v-decorator="[ 'finishTime', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="异步通知地址">
          <a-input placeholder="请输入异步通知地址" v-decorator="['notifyUrl', validatorRules.notifyUrl ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="成功支付的交易拓展编号">
          <a-input-number v-decorator="[ 'extensionId', {}]" />
        </a-form-item>

        <a-form-item label="支付成功的支付渠道" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-select v-decorator="[ 'payChannel', {}]">
            <a-select-option :value="100">等待支付</a-select-option>
            <a-select-option :value="101">支付成功</a-select-option>
            <a-select-option :value="200">取消支付</a-select-option>
            <a-select-option :value="9999">ping++ 支付</a-select-option>
          </a-select>
        </a-form-item>

        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="第三方支付成功的时间">
          <a-date-picker showTime format='YYYY-MM-DD HH:mm:ss' v-decorator="[ 'paymentTime', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="收到第三方系统通知的时间">
          <a-date-picker showTime format='YYYY-MM-DD HH:mm:ss' v-decorator="[ 'notifyTime', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="第三方的流水号">
          <a-input placeholder="请输入第三方的流水号" v-decorator="['tradeNo', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="退款总金额">
          <a-input-number v-decorator="[ 'refundTotal', {}]" />
        </a-form-item>
		
      </a-form>
    </a-spin>
  </a-drawer>
</template>

<script>
  import { httpAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import moment from "moment"

  export default {
    name: "TransactionModal",
    data () {
      return {
        title:"操作",
        visible: false,
        modalWidth:800,
        drawerWidth:900,
        disableSubmit:false,
        modaltoggleFlag:true,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },

        confirmLoading: false,
        form: this.$form.createForm(this),
        validatorRules:{
        appId:{rules: [{ required: true, message: '请输入应用编号!' }]},
        createIp:{rules: [{ required: true, message: '请输入发起交易的 IP!' }]},
        orderId:{rules: [{ required: true, message: '请输入业务线的订单编号!' }]},
        orderSubject:{rules: [{ required: true, message: '请输入订单商品名!' }]},
        orderDescription:{rules: [{ required: true, message: '请输入订单商品描述!' }]},
        price:{rules: [{ required: true, message: '请输入支付金额，单位：分。!' }]},
        status:{rules: [{ required: true, message: '请输入订单状态!' }]},
        notifyUrl:{rules: [{ required: true, message: '请输入异步通知地址!' }]},
        },
        url: {
          // add: "/transaction/transaction/add",
          edit: "/transaction/transaction/edit",
        },
      }
    },
    created () {
    },
    methods: {
      //窗口最大化切换
      toggleScreen(){
        if(this.modaltoggleFlag){
          this.modalWidth = window.innerWidth;
        }else{
          this.modalWidth = 800;
        }
        this.modaltoggleFlag = !this.modaltoggleFlag;
      },
      // add () {
      //   this.edit({});
      // },
      edit (record) {
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'appId','createIp','orderId','orderSubject','orderDescription','orderMemo','price','status','notifyUrl','extensionId','payChannel','tradeNo','refundTotal'))
          //时间格式化
          this.form.setFieldsValue({expireTime:this.model.expireTime?moment(this.model.expireTime):null})
          this.form.setFieldsValue({finishTime:this.model.finishTime?moment(this.model.finishTime):null})
          this.form.setFieldsValue({paymentTime:this.model.paymentTime?moment(this.model.paymentTime):null})
          this.form.setFieldsValue({notifyTime:this.model.notifyTime?moment(this.model.notifyTime):null})
        });

      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      // handleOk () {
      //   const that = this;
      //   // 触发表单验证
      //   this.form.validateFields((err, values) => {
      //     if (!err) {
      //       that.confirmLoading = true;
      //       let httpurl = '';
      //       let method = '';
      //       if(!this.model.id){
      //         httpurl+=this.url.add;
      //         method = 'post';
      //       }else{
      //         httpurl+=this.url.edit;
      //          method = 'put';
      //       }
      //       let formData = Object.assign(this.model, values);
      //       //时间格式化
      //       formData.expireTime = formData.expireTime?formData.expireTime.format('YYYY-MM-DD HH:mm:ss'):null;
      //       formData.finishTime = formData.finishTime?formData.finishTime.format('YYYY-MM-DD HH:mm:ss'):null;
      //       formData.paymentTime = formData.paymentTime?formData.paymentTime.format('YYYY-MM-DD HH:mm:ss'):null;
      //       formData.notifyTime = formData.notifyTime?formData.notifyTime.format('YYYY-MM-DD HH:mm:ss'):null;
      //
      //       console.log(formData)
      //       httpAction(httpurl,formData,method).then((res)=>{
      //         if(res.success){
      //           that.$message.success(res.message);
      //           that.$emit('ok');
      //         }else{
      //           that.$message.warning(res.message);
      //         }
      //       }).finally(() => {
      //         that.confirmLoading = false;
      //         that.close();
      //       })
      //
      //
      //
      //     }
      //   })
      // },
      handleCancel () {
        this.close()
      },


    }
  }
</script>

<style lang="less" scoped>

</style>